package com.ruoyi.salaryBase.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.salaryBase.domain.BaseSalaryChangeVO;
import com.ruoyi.salaryBase.domain.BaseSalaryVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.salaryBase.domain.BaseSalary;
import com.ruoyi.salaryBase.service.IBaseSalaryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工基本薪资Controller
 * 
 * @author cxs
 * @date 2025-05-30
 */
@RestController
@RequestMapping("/salaryBase/salaryBase")
public class BaseSalaryController extends BaseController
{
    @Autowired
    private IBaseSalaryService baseSalaryService;

    /**
     * 查询员工基本薪资列表
     */
    @PreAuthorize("@ss.hasPermi('salaryBase:salaryBase:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseSalaryVO baseSalary)
    {
        startPage();
        List<BaseSalaryVO> list = baseSalaryService.selectBaseSalaryList(baseSalary);
        return getDataTable(list);
    }

    /**
     * 导出员工基本薪资列表
     */
    @PreAuthorize("@ss.hasPermi('salaryBase:salaryBase:export')")
    @Log(title = "员工基本薪资", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseSalary baseSalary)
    {
//        List<BaseSalary> list = baseSalaryService.selectBaseSalaryList(baseSalary);
        ExcelUtil<BaseSalary> util = new ExcelUtil<BaseSalary>(BaseSalary.class);
//        util.exportExcel(response, list, "员工基本薪资数据");
    }

    /**
     * 获取员工基本薪资详细信息
     */
    @PreAuthorize("@ss.hasPermi('salaryBase:salaryBase:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseSalaryService.selectBaseSalaryById(id));
    }

    /**
     * 新增员工基本薪资
     */
    @PreAuthorize("@ss.hasPermi('salaryBase:salaryBase:add')")
    @Log(title = "员工基本薪资", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseSalary baseSalary)
    {
        return toAjax(baseSalaryService.insertBaseSalary(baseSalary));
    }

    /**
     * 修改员工基本薪资
     */
    @PreAuthorize("@ss.hasPermi('salaryBase:salaryBase:edit')")
    @Log(title = "员工基本薪资", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseSalary baseSalary)
    {
        return toAjax(baseSalaryService.updateBaseSalary(baseSalary));
    }

    /**
     * 删除员工基本薪资
     */
    @PreAuthorize("@ss.hasPermi('salaryBase:salaryBase:remove')")
    @Log(title = "员工基本薪资", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseSalaryService.deleteBaseSalaryByIds(ids));
    }

    /**
     * 查询挑衅明细表
     */
//    @PreAuthorize("@ss.hasPermi('salaryBase:salaryBase:change')")
    @GetMapping("/change")
    public TableDataInfo change(BaseSalaryVO baseSalary){
        startPage();
        List<BaseSalaryChangeVO> list = baseSalaryService.selectChangeList(baseSalary);
        return getDataTable(list);
    }

    /**
     * 统计不同部门基本薪资
     */
    @PreAuthorize("@ss.hasPermi('salaryBase:salaryBase:statistics')")
    @GetMapping("/all/statistics")
    public AjaxResult statistics(){
        List<Map<String, Object>> statistics = baseSalaryService.statistics();
        return success(statistics);
    }

    /**
     * 统计特定部门的薪资数据
     */
    @PreAuthorize("@ss.hasPermi('salaryBase:salaryBase:statistics')")
    @GetMapping("/dept/statistics")
    public AjaxResult deptStatistics(BaseSalaryVO baseSalary){
        HashMap statistics = baseSalaryService.deptStatistics(baseSalary);
        return success(statistics);
    }

}
